/**
 * maxlength提示
 * autor : huanran.zhao
 * QQ: 523994553
 * date: 2014-02
 */
var $maxlength = {
	init : function(){
		$(document).on('focus','input[maxlength],textarea[maxlength]',function(){
			if(!$(this).attr('maxlength')) {return;}//无属性数值时 return
			$(this).after('<span id="span_maxlength" class="label label-info" style="position:absolute;z-index:999;">0/0</span>');
			update_maxlength($(this));
		});
		$(document).on('keyup','input[maxlength],textarea[maxlength]',function(){
			if(!$(this).attr('maxlength')) {return;}//无属性数值时 return
			update_maxlength($(this));
		});
		$(document).on('blur','input[maxlength],textarea[maxlength]',function(){
			if(!$(this).attr('maxlength')) {return;}//无属性数值时 return
			$('#span_maxlength').remove();
		});
		function update_maxlength(obj){
			var length = obj.val().length;
			var maxlength = obj.attr('maxlength');
			var str = length+'/'+maxlength;
			$('#span_maxlength').text(str);
		}
	}
};

//初始化执行
$(function(){
	$maxlength.init();
});